<?php
class CorePaymentCalculator {
	protected $objStorage;

    function __construct(&$objStorage) {
        $this->objStorage   =   $objStorage;
    }

    public function calculate() {
        $insInfo =   $this->objStorage->getInsuranceInfo();
        if ($insInfo->getInsuranceGroup() === false){
            foreach ($this->objStorage->getItemList() as $subList) {
                foreach ($subList as &$item) {
	            	if (($val = $item->getModifiedUnitPrice()) > 0) {
	                    // Modified price has higher priority
	                	$item->setOriginalUnitPrice($val);
	                }
	                else {
	                    // Set normalFee to orginalPerUnit
	                    $val    =   $item->getNormalFee();
	                    $item->setOriginalUnitPrice($val);
	                }
                }
            }
        }
        else {
            foreach ($this->objStorage->getItemList() as $subList) {
            	foreach ($subList as &$item) {
	                if (($val = $item->getModifiedUnitPrice()) > 0) {
	                    // Modified price has higher priority
	                    $item->setOriginalUnitPrice($val);
	                }
	                else {
	                    // Set insuranceFee to orginalPerUnit
	                    $val    =   $item->getInsuranceFee();
	                    $item->setOriginalUnitPrice($val);
	                }
            	}
            }
        }
    }
}
?>